#include <stdio.h>

#include "entity.h"

int main(int argc, char** argv)
{
	char readBuf[128] = {0};
	struct List * list = NULL;
	
	FILE* fin;
	

	fin = fopen("./data.txt", "rt");

	if(fin==NULL)
	{
		fprintf(stderr, "open file error...%s\n", "./data.txt");
		exit(1);
	}

	list = createList(createData, 
					  deleteData,
					  duplicateNode,
					  dataCmp,
					  _printInfo);

	if(list==NULL)
	{
		fprintf(stderr, "%s:%s\n", __FUNCTION__, "Create list error...");
		exit(1);
	}

	struct NodeData* data;
//	data->name = (char*)calloc(sizeof(char), 30);
	data = (struct NodeData*)calloc(sizeof(struct NodeData), 1);
	data->name = malloc(sizeof(char)*30);
	memset(data->name, 0, 30);

	while(fgets(readBuf, 127, fin)!=NULL)
	{
		data->u = atoi((const char*)strtok(readBuf, " "));
		char * name = strtok(NULL, " ");
		memcpy(data->name, name, strlen(name)); 
		
		addNodeAtHead(list, (void*)data);
	}
	

	printInfo(list);

	free(data->name);
	free(data);
	deleteList(list);


	getchar();
}

